package com.asia5b.a5mall.middleware.logic.viewmodel.member

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleNetParams
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.base.ResultModel
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
import com.asia5b.a5mall.middleware.utils.removeAllOffGoods
import io.reactivex.functions.Consumer

/**
 * Created by zhangyuncai on 2019/12/21.
 * @Note   会员Fragment逻辑控制器
 */
open class MineFragmentVM : SimpleViewModel() {


    val showGuessLikeLiveData = MutableLiveData<ResultModel<ArrayList<AbsGoodsModel>>>()

   private var page = 1
   private var sumPage = 1000

    /**
     * @Note   加载猜你喜欢商品信息
     * @param  page 分页加载
     */
    fun loadGuessLike(refresh: Int) {
        if (refresh <= 1) {
            page = 1
            sumPage = 1000
        }
        if (page > sumPage) {
            dismissLoadingBar()
            return
        }
        val observable = goodsApi.getMineGuessLike(page, 10).map { it.data }
        baseSubscribe(observable, SimpleNetParams(isShowLoading = false), Consumer { resultModelData ->
            resultModelData?.let {
                sumPage = it.sumPage
                page = it.page + 1//预备加载下一页
//            providerView().showGuessLike(removeAllOffGoods(resultModel.data!!))
                showGuessLikeLiveData.value = resultModelData
            }

        })

    }


}